<?php

namespace App\Admin\Controllers;

use App\Admin\Model\Order;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class OrderController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Order::class, function (Grid $grid) {

            $grid->order_id('ID')->sortable();
            $grid->order_sn('订单编号');
            $grid->cid('联名卡');
            $grid->cdaynum('联名卡使用天数');
            $grid->uname('用户');
            $grid->hid('房源id');
            $grid->master_enjoy('专享');
            $grid->check_in_time('入住时间')->editable('date');
            $grid->check_out_time('退房时间')->editable('date');
            $grid->check_day('入住天数');
            $grid->check_in_people('入住人数');
            $grid->name('预订人-真实姓名');
            $grid->mobile('预订人-手机号码');
            $grid->title('房源标题');
            $grid->house_price('房款总额');
            $grid->order_price('订单总额');
            $grid->order_true_price('订单金额');
            $grid->total_price('实付总额');

            $grid->address('详细地址');
            $grid->status('订单状态 ')->editable('select', [1 =>'待支付', 2 =>'待房东确认' , 3 => '待入住', 4=>'已入住', 5=>'待评价', 7 => '退款中', 8=>'退款成功', 9=>'已取消', 10=>'交易完成', 11=>'删除订单', 12=>'超时未支付已取消']);
            $grid->comment_statusd('评价')->editable('select', [0 => '未评价', 1 => '已评价']);
            $grid->pay_type('支付方式')->display(function($pay_type){
                switch ($pay_type) {
                    case 1:
                        return '微信';
                        break;
                    case 2:
                        return '支付宝';
                        break;
                    case 3:
                        return '银联';
                        break;
                    case 4:
                        return '会员卡';
                        break;
                    default:
                        return "--_--!";
                        break;
                }
            });
            $grid->pay_types('附加')-> display(function ($pay_types) {
                switch ($pay_types) {
                    case 1:
                        return '金币';
                        break;
                    case 2:
                        return '天卡';
                        break;
                    case 3:
                        return '积分天卡';
                        break;

                    default:
                        return "--_--!";
                        break;
                }
            });

            $grid->created_at();
            $grid->updated_at();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Order::class, function (Form $form) {

            $form->display('id', 'ID');

            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
        });
    }
}
